const apiList = {
  getList: "/api/blog/list",
  getListAdmin: "/api/blog/list?isadmin=1;",
  getDetail: "/api/blog/detail",
  newArticle: "/api/blog/new",
  updateArticle: "/api/blog/update",
  deleteArticle: "/api/blog/del",
  login: "/api/user/login"
}

function postData(url, data={}) {
  return $.ajax({
    type: "POST",
    url: url, 
    contentType : 'application/json',
    data: JSON.stringify(data), 
    dataType: 'json'
  })
}

function getList() {
  return $.get(apiList.getList)
}

function getListAdmin() {
  return $.get(apiList.getListAdmin)
}


function getDetail(id) {
  return $.get(`${apiList.getDetail}?id=${id}`)
}

function newArticle(params) {
  return postData(apiList.newArticle, params)
}

function editArticle(id, params) {
  return postData(`${apiList.updateArticle}?id=${id}`, params)
}

function deleteArticle(id, params) {
  return postData(`${apiList.deleteArticle}?id=${id}`, params)
}

function login(params) {
  return postData(apiList.login, params)
}

export default {
  getList,
  getListAdmin,
  getDetail,
  newArticle,
  editArticle,
  deleteArticle,
  login
}